#ifndef xpack_lang_cxx_count_of
#define xpack_lang_cxx_count_of
#pragma push_macro("xuser")
#undef  xuser
#define xuser mixc::lang_cxx::inc
#include"define/base_type.hpp"
#include"lang/cxx/find.hpp"
#include"lang/cxx.hpp"
#include"meta/unsigned_type.hpp"
#pragma pop_macro("xuser")

namespace mixc::lang_cxx::origin{
    template<class item_t>
    constexpr auto expect_ascii = [](uxx, item_t const & value){
        return inc::unsigned_type<item_t>(value) < 128;
    };

    template<class item_t>
    constexpr auto expect_unicode = [](uxx, item_t const & value){
        if constexpr (sizeof(item_t) == 1){
            return (inc::unsigned_type<item_t>(value) & 0xc0) == 0xc0;
        }
        if constexpr (sizeof(item_t) >= 2){
            return (inc::unsigned_type<item_t>(value)) > 127;
        }
    };
}

namespace mixc::lang_cxx{
    using namespace origin;

    template<class item_t>
    inline uxx cxx<item_t>::count_of(the_cref_t pattern, invoke_compare_t compare) const {
        return xthe.find(pattern, compare, [&](auto const &){});
    }

    template<class item_t>
    inline uxx cxx<item_t>::count_of(item_cref_t pattern, invoke_compare_t compare) const {
        return xthe.find(pattern, compare, [&](auto const &){});
    }

    template<class item_t>
    inline uxx cxx<item_t>::count_of(invoke_count_of_t iterator) const {
        uxx i           = 0;
        uxx count       = 0;
        uxx length      = xthe->length;

        for(; i < length; i++){
            if (iterator(i, xthe[i])){
                count++;
            }
        }
        return count;
    }
}

#endif
